package com.qing.library_manager.controller.book;

import com.qing.library_manager.domain.dto.BookDTO;
import com.qing.library_manager.domain.query.BookQueryByName;
import com.qing.library_manager.domain.query.BookQueryByPage;
import com.qing.library_manager.service.manager.book.bookService;
import com.qing.library_manager.common.util.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;


/**
 *
 */
@RestController
@RequestMapping("/api/book")
@Api(tags = {"图书模块"})
public class bookController {

    private final bookService bookService;

    public bookController(com.qing.library_manager.service.manager.book.bookService bookService) {
        this.bookService = bookService;
    }

    /**
     *  新增图书
     * @param bookDTO
     * @return
     */
    @ApiOperation("新增图书")
    @PostMapping("/addBook")
    public ResponseResult increaseBook(@RequestBody BookDTO bookDTO) {
        return bookService.increaseBook(bookDTO);
    }

    /**
     *  更新图书
     * @param bookDTO
     * @return
     */
    @ApiOperation("更新图书")
    @PostMapping("/updateBook")
    public ResponseResult updateBook(@RequestBody BookDTO bookDTO) {
        return bookService.updateBookByName(bookDTO);
    }

    /**
     *  删除图书
     * @param bookShowId
     * @return
     */
    @ApiOperation("删除图书")
    @PostMapping("/deleteBook/{bookShowId}")
    public ResponseResult deleteBook(@PathVariable int bookShowId) {
        return bookService.deleteBookByName(bookShowId);
    }

    /**
     *  查询图书根据特定条件
     * @param
     * @return
     */
    @ApiOperation("查询图书根据特定条件")
    @GetMapping("/queryBookByName")
    public ResponseResult queryBookByName(BookQueryByName bookQueryByName) {
        return bookService.queryAllBookInit(bookQueryByName);
    }

    /**
     *  根据id查询图书信息
     * @param
     * @return
     */
    @ApiOperation("根据id查询图书信息")
    @GetMapping("/queryBookById/{bookShowId}")
    public ResponseResult queryBookById(@PathVariable int bookShowId) {
        return bookService.queryBookById(bookShowId);
    }

    /**
     *  分页查询书籍信息
     * @param
     * @return
     */
    @ApiOperation("分页查询书籍信息")
    @PostMapping("/queryBookById/{pageNum}/{pageSize}")
    public ResponseResult queryBookByPage(@PathVariable int pageNum,
                                          @PathVariable int pageSize,
                                          @RequestBody BookQueryByPage bookQueryByPage
    ) {
        return bookService.queryBookByPage(pageNum,pageSize,bookQueryByPage);
    }

    /**
     *  获取全部数据
     * @param
     * @return
     */
    @ApiOperation("获取全部数据")
    @GetMapping("/queryAllBook")
    public ResponseResult queryAllBook() {
        return bookService.queryAllBook();
    }

}
